 var wsUrl = 'ws://39.98.144.29:6062';

var webSocket = new WebSocket(wsUrl);

//实例化对象onOpen 属性
webSocket.onopen = function (evt) {
    webSocket.send("chart.js");
    console.log("connected-swoole-success");
}
//实例化对象onmessage
webSocket.onmessage = function (evt) {
    push(evt.data);
    console.log('ws-server-request-data:' + evt.data);
}

//实例化close事件
webSocket.onclose = function (evt) {
    console.log('colse-swoole');
}
//onerror
webSocket.onerror = function (evt, e) {
    console.log("error:" + evt.data)
}
function push(data)
{
    data = JSON.parse(data);
    var html = '<div class="comment">'
    html+= '<span>'+data.user+'</span>'
    html+=   '<span>&nbsp&nbsp'+data.content+'</span>'
    html+= '</div>'

     $('#comments').append(html);
}